<?php if (!defined('THINK_PATH')) exit(); /*a:4:{s:78:"/www/wwwroot/api.bjxlxd.com/public/../application/business/view/goods/add.html";i:1599613663;s:70:"/www/wwwroot/api.bjxlxd.com/application/business/view/public/help.html";i:1598261831;s:70:"/www/wwwroot/api.bjxlxd.com/application/business/view/public/menu.html";i:1598405729;s:72:"/www/wwwroot/api.bjxlxd.com/application/business/view/public/header.html";i:1597137300;}*/ ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>后台管理</title>

    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">


    <!-- Styles -->
    <link href="/static/admin/other/fontawesome-all.min.css" rel="stylesheet">
    <link href="/static/admin/css/lib/themify-icons.css" rel="stylesheet">
    <link href="/static/admin/css/lib/mmc-chat.css" rel="stylesheet" />
    <link href="/static/admin/css/lib/owl.carousel.min.css" rel="stylesheet" />
    <link href="/static/admin/css/lib/owl.theme.default.min.css" rel="stylesheet" />
    <link href="/static/admin/css/lib/sidebar.css" rel="stylesheet">
    <link href="/static/admin/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="/static/admin/css/lib/nixon.css" rel="stylesheet">
    <link href="/static/admin/css/style.css" rel="stylesheet">
    
</head>

<body>

<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <ul>
                <li><a href="/admin/Index"><i class="ti-home"></i> 数据概览</a></li>

                <?php if(in_array((\think\Cookie::get('admin_id')), explode(',',"1"))): ?>
                <li>
                    <a class="sidebar-sub-toggle"><i class="ti-layout-grid4-alt"></i> 后台栏目管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="/admin/Menu">栏目列表</a></li>
                    </ul>
                </li>
                <li><a href="/admin/AdminUser"><i class="ti-github"></i> 后台管理员</a></li>
                <?php endif; if(is_array($topMenu) || $topMenu instanceof \think\Collection || $topMenu instanceof \think\Paginator): $i = 0; $__LIST__ = $topMenu;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;if(!empty($vo['secondMenu'])): ?>
                <li>
                    <a class="sidebar-sub-toggle"><i class="<?php echo $vo['icon']; ?>"></i> <?php echo $vo['name']; ?> <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <?php if(is_array($vo['secondMenu']) || $vo['secondMenu'] instanceof \think\Collection || $vo['secondMenu'] instanceof \think\Paginator): $i = 0; $__LIST__ = $vo['secondMenu'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vi): $mod = ($i % 2 );++$i;?>
                        <li><a href="/admin/<?php echo $vi['class']; ?>"><?php echo $vi['name']; ?></a></li>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                    </ul>
                </li>
                <?php else: ?>
                <li><a href=""><i class="<?php echo $vo['icon']; ?>"></i> <?php echo $vo['name']; ?></a></li>
                <?php endif; endforeach; endif; else: echo "" ;endif; ?>
                <!--<li><a href="/admin/loginOut"><i class="ti-close"></i> Logout</a></li>-->
            </ul>
        </div>
    </div>
</div>


<div class="header">
    <div class="pull-left">
        <div class="logo">
            <a href="index.html"></a>
        </div>
        <div class="hamburger sidebar-toggle">
            <span class="ti-menu"></span>
        </div>
    </div>
    <div class="pull-right p-r-15">
        <ul>
            <li class="header-icon dib">
                <i class="ti-bell"></i>
                <div class="note-count">0</div>
                <div class="drop-down">
                    <div class="dropdown-content-body">
                        <ul>
                            <li>
                                <a href="/admin/demandList">
                                    <div class="notification-content">
                                        <div class="notification-heading">&nbsp;</div>
                                        <div class="notification-heading">有新的活动需求单</div>
                                        <div class="notification-heading">&nbsp;</div>
                                    </div>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </li>

            <li class="header-icon dib">
                <img class="avatar-img" src="/static/admin/img/avatar/1.jpg" alt="" /> <span class="user-avatar"><?php echo \think\Cookie::get('admin_name'); ?> </span>
            </li>
        </ul>
    </div>
</div>


<script>
    window.onload = function(){
        getNum();
    }
    var ref = "";
    ref = setInterval(function(){
        getNum();
    },10000);
    function getNum(){
        $.ajax({
            type: 'POST',
            url: '/admin/Demand/getNum',
            data:{
            },
            dataType: 'json',
            success: function(data){
                $(".note-count").html(data.num);
            },
        });
    }
</script>

<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <h1></h1>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <ol class="breadcrumb text-right">
                                <li><a href="#"><?php echo $crumbs['oneMenuName']; ?></a></li>
                                <li class="active"><?php echo $crumbs['twoMenuName']; ?></li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            <div class="main-content">
                
<div class="main-content">
    <form enctype="multipart/form-data" method="post" id="topform">
        <input type="hidden" value="<?php echo $id; ?>" name="id">
        <div class="row">
            <div class="col-lg-6">
                <div class="card alert">
                    <div class="card-header">
                        <h4 >商品添加/修改</h4>
                    </div>
                    <button type="button" id="add_specs" class="btn btn-success m-b-10 m-l-5">添加规格</button>
                    <div class="card-body">
                        <div class="basic-form">
                            <div class="form-group">
                                <label>商家选择</label>
                                <select class="form-control" name="b_id">
                                    <?php if(is_array($business) || $business instanceof \think\Collection || $business instanceof \think\Paginator): $i = 0; $__LIST__ = $business;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo['id']; ?>"
                                            <?php if($vo['id'] == $data['b_id']): ?>selected<?php endif; ?>
                                    ><?php echo $vo['name']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>是否团购</label>
                                <select class="form-control" name="is_group_buy" id="is_group_buy">
                                    <option value="1" <?php if($data['is_group_buy'] == '1'): ?>selected<?php endif; ?> >-- 单品 --</option>
                                    <option value="2" <?php if($data['is_group_buy'] == '2'): ?>selected<?php endif; ?> >-- 团购 --</option>
                                    <!--<option value="3" <?php if($data['is_group_buy'] == '3'): ?>selected<?php endif; ?> >&#45;&#45; 全部 &#45;&#45;</option>-->
                                </select>
                            </div>
                            <div class="form-group">
                                <label>商品名称</label>
                                <input type="text" name="goods_name" id="goods_name" class="form-control" value="<?php echo $data['goods_name']; ?>" placeholder="商品名称">
                            </div>
                            <div class="form-group">
                                <label>商品分类</label>
                                <select class="form-control" name="type_id" id="type_id">
                                    <?php if(is_array($types) || $types instanceof \think\Collection || $types instanceof \think\Paginator): $i = 0; $__LIST__ = $types;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo['id']; ?>"
                                            <?php if($vo['id'] == $data['type_id']): ?>selected<?php endif; ?>
                                    ><?php echo $vo['name']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>商品封面图</label>
                                <input type="text" name="img" id="img" class="form-control" value="<?php echo $data['img']; ?>" placeholder="url (七牛云的外链)">
                            </div>
                            <div class="form-group">
                                <label>商品小图</label>
                                <input type="text" name="imgs" id="imgs" class="form-control" value="<?php echo $data['imgs']; ?>" placeholder="url (七牛云的外链), 多个用逗号隔开">
                            </div>

                            <div class='card-body' >
                                <table class='table table-responsive'>
                                    <thead>
                                    <tr>
                                        <th></th>
                                        <th>规格名称</th>
                                        <th>非团购价格</th>
                                        <th>库存</th>
                                        <th>团价数量及价格</th>
                                    </tr>
                                    </thead>
                                    <tbody id="down_add_specs">
                                        <?php if($specs): foreach($specs as $k => $v): ?>
                                                <tr>
                                                    <td><button type='button' onclick='del_specs(this)'>删除</button></td>
                                                    <td><?php echo $v['specs_name']; ?></td>
                                                    <td><?php echo $v['price']; ?></td>
                                                    <td><?php echo $v['stock']; ?></td>
                                                    <td><?php echo $v['t_price_number']; ?></td>
                                                    <input type='hidden'  name='specs_name[]' value=<?php echo $v['specs_name']; ?>>
                                                    <input type='hidden' name='stock[]' value=<?php echo $v['stock']; ?>>
                                                    <input type='hidden' name='price[]' value=<?php echo $v['price']; ?>>
                                                    <input type='hidden' name='t_price_number[]' value=<?php echo $v['t_price_number']; ?>>
                                                </tr>
                                            <?php endforeach; endif; ?>
                                    </tbody>
                                </table>
                            </div>

                            <div class="form-group">
                                <label>商品详情</label>
                                <div id="editor" ><?php echo $data['desc']; ?></div>
                                <textarea id="desc" name="desc" style="display: none;"></textarea>
                            </div>

                            <!--<div style="display: none;" id="hidden_input"></div>-->

                            <button type="button" id="submit" class="btn btn-success m-b-10 m-l-5">确定</button>
                        </div>
                    </div>
                </div>
            </div><!-- /# column -->
        </div><!-- /# row -->
    </form>
</div><!-- /# container-fluid -->


            </div>

        </div><!-- /# container-fluid -->
    </div><!-- /# main -->
</div><!-- /# content wrap -->

<script src="/static/admin/js/lib/jquery.min.js"></script><!-- jquery vendor -->
<script src="/static/admin/js/lib/jquery.nanoscroller.min.js"></script><!-- nano scroller -->
<script src="/static/admin/js/lib/sidebar.js"></script><!-- sidebar -->
<script src="/static/admin/js/lib/bootstrap.min.js"></script><!-- bootstrap -->
<script src="/static/admin/js/lib/mmc-common.js"></script>
<script src="/static/admin/js/lib/mmc-chat.js"></script>
<script src="/static/admin/js/lib/owl-carousel/owl.carousel.min.js"></script>
<script src="/static/admin/js/lib/owl-carousel/owl.carousel-init.js"></script>
<script src="/static/admin/layer/layer.js"></script>
<script src="/static/admin/layer/common.js"></script>

<script src="/static/admin/js/lib/wangEditor-3.1.1/release/wangEditor.js"></script>
<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E('#editor')
    var $text1 = $('#desc')
    editor.customConfig.uploadImgShowBase64 = true

    editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $text1.val(html)
    }
    editor.create()
    // 初始化 textarea 的值
    $text1.val(editor.txt.html())
</script>

<script>

    function del_specs(obj){
        $(obj).parent('td').parent('tr').remove()
    }

    $('#add_specs').click(function () {
        layer.open({
            type: 2,
            area: ['600px', '600px'],
            title: '添加商品规格',
            content: '/admin/addGoodsSpecs',
        });
    })

    function add_specs(specs, price, stock, t_price_number){
        var html = '';
        html +=            "<tr>";
        html +=               "<td><button type='button' onclick='del_specs(this)'>删除</button></td>";
        html +=               "<td>"+specs+"</td>";
        html +=                "<td>"+price+"</td>";
        html +=                "<td>"+stock+"</td>";
        html +=                "<td>"+t_price_number+"</td>";
        html +=                "<input type='hidden'  name='specs_name[]' value="+specs+">"
        html +=                "<input type='hidden' name='stock[]' value="+stock+">"
        html +=                "<input type='hidden' name='price[]' value="+price+">"
        html +=                "<input type='hidden' name='t_price_number[]' value="+t_price_number+">"
        html +=            "</tr>";

        // var input = '';
        // input += "<input type='text' name='specs_name[]' value="+specs+">"
        // input += "<input type='text' name='stock[]' value="+stock+">"
        // input += "<input type='text' name='price[]' value="+price+">"
        // input += "<input type='text' name='t_price_number[]' value="+t_price_number+">"


        $('#down_add_specs').append(html)
        // $('#hidden_input').append(input)
    }
</script>

<script>
    $('#submit').click(function(){
        var goods_name = $('#goods_name').val();
        var img = $('#img').val();
        // var price = $('#price').val();
        // var t_price = $('#t_price').val();
        // var stock = $('#stock').val();
        var down_add_specs = $('#down_add_specs').html()
        var desc = $('#desc').val();

        if(!goods_name){ error('商品名称有误'); return; }
        if(!img){ error('商品封面图有误'); return; }
        // if(!price){ error('商品价格有误'); return; }
        // if(!t_price){ error('团购价格有误'); return; }
        // if(!stock){ error('库存有误'); return; }
        if(!down_add_specs){ error('请添加商品规格'); return; }
        if(!desc){ error('商品描述有误'); return; }

        var formData = new FormData($( "#topform" )[0]);

        var id = $('input[name="id"]').val();
        if(id){
            var url = "<?php echo url('/admin/editSaasGoods'); ?>";
        }else{
            var url = "<?php echo url('/admin/addSaasGoods'); ?>";
            formData.delete("id");
        }

        $.ajax({
            type:'post',
            url:url,
            data:formData,
            cache: false,
            contentType: false,
            processData: false,
            success:function(res){
                if(res.code){
                    redirect_success(res.msg, res.url);
                }else{
                    error(res.msg);
                }
            }
        });
    });
</script>


</body>

</html>